<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">

	</head>
	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item type">
								<label class="layui-form-label">类型</label>
								<div class="layui-input-block site_rebate_member"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">名称</label>
								<div class="layui-input-block">
									<input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							<!-- <div class="layui-form-item">
								<label class="layui-form-label">数量</label>
								<div class="layui-input-block">
									<input type="text" name="quantity" placeholder="请输入数量" autocomplete="off" class="layui-input">
								</div>
							</div> -->

							<div class="layui-form-item">
								<div class="layui-inline quantity">
									<label class="layui-form-label">数量</label>
									<div class="layui-input-block">
										<input type="text" name="quantity" placeholder="请输入数量" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline start_end">
									<label class="layui-form-label">数量起止</label>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="start" placeholder="数量起" autocomplete="off" class="layui-input">
									</div>
									<div class="layui-form-mid">-</div>
									<div class="layui-input-inline" style="width: 100px;">
										<input type="text" name="end" placeholder="数量止" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">奖励金额</label>
									<div class="layui-input-inline">
										<input type="text" name="amount" placeholder="请输入奖励金额" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">结算类型</label>
									<div class="layui-input-inline site_rebate_settlement"></div>
								</div>
							</div>

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js"></script>
		<script src="../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			// console.log(_data.id);

			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;

				on_off_show('radio')
				site_rebate_member_show('radio')
				site_rebate_settlement_show('radio')

				if (getParam('type') == 1) {
					$('.start_end').addClass('layui-hide')
				} else {
					$('.start_end').removeClass('layui-hide')
				}
				if (getParam('type') == 2 || getParam('type') == 3) {
					$('.quantity').addClass('layui-hide')
				} else {
					$('.quantity').removeClass('layui-hide')
				}
				if (_data.id) {
					initdata()
					$('.type').addClass('layui-hide')
				} else {
					$('.type').removeClass('layui-hide')
				}

				// initproductshow('option')
				//监听提交
				form.on('radio(type)', function(data) {
					var value = data.value
					if (value == 1) {
						$('.start_end').addClass('layui-hide')
					} else {
						$('.start_end').removeClass('layui-hide')
					}
					if (value == 2 || value == 3) {
						$('.quantity').addClass('layui-hide')
					} else {
						$('.quantity').removeClass('layui-hide')
					}
				});
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);

					console.log(_data);
					layer.confirm('确定提交数据？', function() {
						loading();
						if (_data.id) {
							submitdata(server.updatesite_rebate);
						} else {
							delete _data.id
							submitdata(server.addsite_rebate);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				function initdata() {
					$.post(server.querysite_rebatedetail, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								var data = res.site_rebate

								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

			});
		</script>
	</body>
</html>
